package com.pany.rememberpass;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

public class ArryListViewActivity extends AppCompatActivity {
    private ListView listView;
    private ArrayList<String> listData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_arry_list_view);
        listView = findViewById(R.id.lv);

        listData = new ArrayList<>();

        for (int i = 0; i < 50; i++) {

            listData.add("这个是item " + i);
        }

        ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, listData);

        listView.setAdapter(stringArrayAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Toast.makeText(ArryListViewActivity.this, "点击了第 " + i + "条数据--", Toast.LENGTH_SHORT).show();
            }
        });

        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(ArryListViewActivity.this, "长安了第 "+ i + "条数据+++++", Toast.LENGTH_SHORT).show();

                return true;// 消费了点击事件
            }
        });
    }
}